package com.chen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chen.pojo.Album;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author chenchao

 */

@Mapper
public interface AlbumMapper extends BaseMapper<Album> {

    // 直接删除整个相册
    @Delete("delete from album where name = #{arg0} and category = #{arg1}")
    int deleteAllCategory(String arg0, String arg1);

    // 直接删除某一张图片
    @Delete("delete from album where id = #{id}")
    int deleteOneCategory(int id);

    //查询某一个
    @Select("select * from album where name=#{name}")
    List<Album> albumList(String name);

    //查询某一个
    @Select("select * from album where id=#{id}")
    Album getAlbumById(int id);

    //校验该用户下是否已经存在相同名称的相册
    @Select("select count(0) from album where name = #{arg0} and op = 0 and category = #{arg1}")
    int isExistSameCategoryByName(String arg0, String arg1);

    @Select("select count(*) as count,category,albums,intro,name,id from album group by category")
    List<Album> categoryImg();

    //根据分类进行查找
    @Select("select * from album where name = #{arg0} and category=#{arg1} ")
    List<Album> categoryList(String arg0, String arg1);


    @Select("select (select count(0) from album where name=#{name} ) as count,a.* from album a  where name=#{name} and op = 0")
    List<Album> categoryImgs(String name);



}
